import config from '@/config';
export const upload = (callback) => {
    const token = uni.getStorageSync('App-Token');

    uni.chooseImage({
      count: 4, //默认9
      sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
      //sourceType: ['album'], //从相册选择
      success: (res) => {
        uni.uploadFile({
            url: config.baseUrl + '/common/upload',
          filePath: res.tempFilePaths[0],
          name: 'file',
          header: {
            Authorization: 'Bearer ' + token, // 添加token到请求头
          },
          success: (uploadFileRes) => {
              let result = JSON.parse(uploadFileRes.data);
              
            if (result.code ==200) {
              callback(result);
            } else {
              uni.showToast({
                title: result.msg,
                icon: 'none',
                duration: 2000
              });
            }
          }
        });
      }
    });
  }